/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.data;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;

import edu.bsu.android.gtv.apps.bconnected.objects.Event;
import edu.bsu.android.gtv.apps.bconnected.parser.ParserFactory;
import edu.bsu.android.gtv.apps.bconnected.parser.ServiceParser;
import edu.bsu.android.gtv.apps.bconnected.util.Constants;

/**
 * Data layer for the {@link Event} object
 * @author Kyle Parker, University Computing Services
 */
public class EventData {
	private static ArrayList<Event> mEvents;

    /**
     * Loads an ArrayList<Event> from the service handler containing the list of events based on a month and year
     * @param month
     * @param year
     * @param activity - used by the {@link ParserFactory} to retrieve the demo_account shared preference - this will determine what
     * 					 data source to use for the service handler.
     */
    public static void initializeEvent(int month, int year, Activity activity) {
    	List<String> querystringParms = new ArrayList<String>(3);
    	querystringParms.add(Constants.QUERYSTRING_MONTH + Integer.toString(month));
    	querystringParms.add(Constants.QUERYSTRING_YEAR + Integer.toString(year));
    	querystringParms.add(Constants.QUERYSTRING_QUERY_ID + Constants.QUERY_EVENT_MONTH_YEAR);
			
		ServiceParser parser = ParserFactory.getParser(Constants.SERVICE_TYPE_EVENT, querystringParms, activity);
		mEvents = parser.parseEvent();
    }

    /**
     * Loads an ArrayList<Event> from the service handler containing the event information based on the event ID
     * @param eventID
     * @param activity - used by the {@link ParserFactory} to retrieve the demo_account shared preference - this will determine what
     * 					 data source to use for the service handler.
     */
    public static void initializeEvent(int eventID, Activity activity) {
    	List<String> querystringParms = new ArrayList<String>(3);
    	querystringParms.add(Constants.QUERYSTRING_EVENT_ID + Integer.toString(eventID));
    	querystringParms.add(Constants.QUERYSTRING_QUERY_ID + Constants.QUERY_EVENT_ID);
			
		ServiceParser parser = ParserFactory.getParser(Constants.SERVICE_TYPE_EVENT_INFO, querystringParms, activity);
		mEvents = parser.parseEvent();
    }
    
    /**
     * Returns the integer value of the {@link Event} object size
     * @return mEvents.size() | 0
     */
    public static int getEventCount() {
    	if (mEvents == null) {
    		return 0;
    	} else {
            return mEvents.size();
    	}
    }

    /**
     * Returns an event object at the index specified
     * @param i - the index of the object to be returned
     * @return mEvents.get(i);
     */
    public static Event getEvent(int i) {
        return mEvents.get(i);
    }

    /**
     * Returns the ArrayList<Event>
     * @return mEvents
     */
    public static ArrayList<Event> getEvents() {
        return mEvents;
    }
}
